package com.example.rfidserver.ticket;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.rfidserver.R;
import com.example.rfidserver.dao.TicketDao;
import com.example.rfidserver.dao.UserDao;
import com.example.rfidserver.pojo.Ticket;
import com.example.rfidserver.pojo.User;
import com.example.rfidserver.ticket.adapter.TicketAdapter;
import com.example.rfidserver.ticket.adapter.TicketSubAdapter;
import com.example.rfidserver.ticket.subactivity.TicketAddActivity;
import com.example.rfidserver.ticket.subactivity.TicketDeleteActivity;
import com.example.rfidserver.ticket.subactivity.TicketModifyActivity;
import com.example.rfidserver.utils.DbHelper;

import java.util.List;

public class TicketManagerActivity extends AppCompatActivity {

    private DbHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ticket_manager);
        UserDao userDao = new UserDao();
        List<User> users = userDao.getUserInfo();
        initview(this,users);
    }

    @Override
    protected void onResume() {
        super.onResume();
        UserDao userDao = new UserDao();
        List<User> users = userDao.getUserInfo();
        initview(this,users);
    }

    public void initview(Context context, List<User> users){
        //获得修改ticket的item
        final ListView mylistview = findViewById(R.id.mylistview);
        final TicketAdapter ticketAdapter = new TicketAdapter(context,users);
        mylistview.setAdapter(ticketAdapter);
        //设置Item项的点击事件
        mylistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //得到点击的该用户的所有信息
                //Ticket item_user = ticketAdapter.getItem(position);
                //System.out.println(item_user);

            }
        });
    }


    public void onClick(View view){
        switch (view.getId()){
            case R.id.ticketManager_del_btn:
                Intent delintent = new Intent(TicketManagerActivity.this, TicketDeleteActivity.class);
                startActivity(delintent);
                break;
            case R.id.ticketManager_add_btn:
                Intent addintent = new Intent(TicketManagerActivity.this, TicketAddActivity.class);
                startActivity(addintent);
                break;
            case R.id.ticketManager_modify_btn:
                Intent modintent = new Intent(TicketManagerActivity.this, TicketModifyActivity.class);
                startActivity(modintent);
                break;
        }

    }


 }